﻿<!doctype html>
<html>
<head>
    <meta charset="utf-8">

    <title>div随机变色3</title>
    <style>
        #div1 {
            width: 300px;
            height: 300px;
            border: 1px solid #000;
        }
    </style>
    <script>
        window.onload = function () {
            var oBtn = document.getElementById('btn1');
            var oDiv = document.getElementById('div1');

            oBtn.onclick = function () {
                oDiv.style.background = 'rgb(' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ')';
            }
        }
    </script>
</head>

<body>
<input type="button" value="变色" id="btn1">
<div id="div1"></div>
</body>
</html>
